export function debounce<T extends (...args: any[]) => void>(
  fn: T,
  delay = 100,
) {
  let timer: ReturnType<typeof setTimeout> | undefined;
  return function (this: unknown, ...args: any[]) {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      timer = undefined;
      fn.apply(this, args);
    }, delay);
  } as T;
}
